import java.util.Random;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //计算 : 1/1-1/2+1/3-1/4+1/5......+1/99-1/100
        double sum =0;
        int flg =1;
        for (int i = 1; i <=100 ; i++) {
            sum+=1*1.0/i*flg;
            flg=-flg;
        }
        System.out.println(sum);



    }
    public static void main6(String[] args) {
        //求两个整数的最大公约数
        int a = 24 ;
        int b = 18;
        int c = a%b;
        while(c!=0){
            a=b;
            b=c;
            c=a%b;
        }
        System.out.println(b);
    }
    public static void main5(String[] args) {
        //数字9出现的次数，编写程序数一下 1-100的所有整数中出现多少个数字9
        int count = 0;
        for (int i = 1; i <100 ; i++) {
            if (i%10==9){
                count++;
            }else if (i/10==9){
                count++;
            }
        }
        System.out.println(count);




    }
    public static void main4(String[] args) {
        int a=24;
        int b=18;


    }
    public static void main3(String[] args) {
        //求0〜999999间的水仙花数
        for (int i = 0; i < 999999; i++) {
            int count= 0;         //1.计算数字的个数
            int temp = i;
            int sum=0;
            while (temp!=0){
                temp/=10;
                count++;          //count = 3
            }
            temp = i;             //2.计算数字每一位
            while (temp !=0){     //3.将数字每一位的个数次幂之和与数字进行比较
                sum +=Math.pow(temp %10,count);
                temp/=10;
            }
            if(sum == i){
                System.out.println(sum);
            }
        }



    }
    public static void main2(String[] args) {
        int count = 5;
        Scanner scanner = new Scanner(System.in);
        Random random = new Random(); //生成随机数的工具
        int toguess = random.nextInt(100); //随机数范围 [0,100)
        System.out.println("请随机输入一个 0—100 的数字：");
        while(count !=0){
            int num = scanner.nextInt();
            if(num >toguess){
                count--;
                System.out.println("猜大了！"+"你还有"+count+"次机会");
            }else if(num < toguess){
                count--;
                System.out.println("猜小了！"+"你还有"+count+"次机会");
            }else{
                System.out.println("猜对了");
                break;
            }
        }
        scanner.close();


    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int sum = 0 ;
        int num =0;

        while(scanner.hasNextInt()){
            int temp = scanner.nextInt();
            sum += temp;
            num++;

        }
        System.out.println("sum="+sum+" "+"num="+num);
        System.out.println("平均数："+sum/num);

        scanner.close();
    }
}
